﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace clockerEditor
{
    public class Buttons
    {
        //variables

        public bool clicked = false;
        public bool prevClicked = false;
        bool hover = false;
        Texture2D texture;
        public Vector2 position;
        Rectangle collisionRect;


        // methods

        public Buttons( Texture2D texture , Vector2 position)
        {
            this.texture = texture;
            this.position = position;

        }

        public virtual void update() 
        {
            // takes the measurements of the rectangle and creates a hitbox around it
            collisionRect = new Rectangle((int)position.X, (int)position.Y, texture.Width,
                texture.Height);

            //gets the position and state of the mouse
            MouseState mouse = Mouse.GetState();
            Rectangle mousePosition = new Rectangle(mouse.X, mouse.Y, 1, 1);

            if (mousePosition.Intersects(collisionRect)) // is it hovering the button
            {
                hover = true;
            }
            else
            {
                hover = false;
            }

            //are you clicked?
            if (mousePosition.Intersects(collisionRect) && mouse.LeftButton ==
                    ButtonState.Pressed && !prevClicked)
            {
                clicked = true;
            }
            else
            {
                clicked = false;
            }



        }

        public virtual void effect()  // gonna be overwriten
        {
        }

        public void draw()  
        {
            if (hover)
            {
                Game1.spriteBatch.Draw(texture, position, Color.MidnightBlue);
            }
            else
            {
                Game1.spriteBatch.Draw(texture, position, Color.White);
            }
        }
    }
}
